﻿using Kingdee.BOS.Core.DynamicForm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.FormElement;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.JSON;
using Kingdee.BOS.App.Data;
using System.Data;

namespace LiMinCRMPlugin
{
    /// <summary>
    /// 销售订单表单插件      2024年4月13日17:12:39
    /// </summary>
    [System.ComponentModel.Description("发货通知单表单插件")]
    [HotUpdate]
    public class DeliveryNoticeForm : AbstractBillPlugIn
    {
        public override void BeforeSave(BeforeSaveEventArgs e)
        {
            base.BeforeSave(e);
            if (1 != 1)//小于表示拿掉，0711
            {

                //自动匹配库存返回
                if (this.View.Model.GetValue("FDeliveryOrgID") != null)
                {
                    DynamicObject Org = this.View.Model.GetValue("FDeliveryOrgID") as DynamicObject;//组织 公司代码 
                    string OrgNumber = "";//发货组织
                    if (Org != null)
                    {
                        OrgNumber = Convert.ToString(Org["Number"]);//组织
                        if (OrgNumber == "1012" || OrgNumber == "1013")
                        {


                            if (this.View.Model.GetValue("FLot", 0) != null && this.View.Model.GetValue("FStockID", 0) != null)
                            {

                                if (this.View.Model.GetValue("FLot", 0).ToString() != "" && this.View.Model.GetValue("FLot", 0).ToString() != " ")
                                {

                                }
                                else
                                {

                                    if (this.View.Model.GetValue("F_DEV_Seasoning") != null)
                                    {
                                        string Seasoning = this.View.Model.GetValue("F_DEV_Seasoning").ToString();
                                        if (Seasoning == "0")
                                        {
                                            ((IDynamicFormViewService)this.View).ButtonClick("F_RDLV_btnStock", string.Empty);//添加分录

                                        }
                                    }
                                    else
                                    {
                                        ((IDynamicFormViewService)this.View).ButtonClick("F_RDLV_btnStock", string.Empty);//添加分录
                                    }

                                }
                            }
                            else
                            {
                                if (this.View.Model.GetValue("F_DEV_Seasoning") != null)
                                {
                                    string Seasoning = this.View.Model.GetValue("F_DEV_Seasoning").ToString();
                                    if (Seasoning == "0")
                                    {
                                        ((IDynamicFormViewService)this.View).ButtonClick("F_RDLV_btnStock", string.Empty);//添加分录

                                    }
                                }
                                else
                                {
                                    ((IDynamicFormViewService)this.View).ButtonClick("F_RDLV_btnStock", string.Empty);//添加分录
                                }
                            }

                        }
                    }
                }


            }

            //自动默认调货仓库
            if (this.View.Model.GetValue("F_DEV_Seasoning") != null)
            {
                string Seasoning = this.View.Model.GetValue("F_DEV_Seasoning").ToString();//获取调货状态
                if (Seasoning == "1")
                {

                    int entryCurrentRowIndex = this.Model.GetEntryRowCount("FEntity");
                    for (int i = 0; i < entryCurrentRowIndex; i++)
                    {
                        //if (this.View.Model.GetValue("FStockID", i) == null || this.View.Model.GetValue("FStockID", i).ToString() == "0")
                        //{
                            this.View.Model.SetItemValueByNumber("FStockID", "THC", i);

                        //}


                    }
                }
            }


        }



    }
}
